% 更新为新的种群
function population_end = GA_replacePopulation(population,children)
    global fitnessValues_pop fitnessValues_chi replaceRate bestIndividual_fitnessValue
    global bestIndividual 
    populationSize = size(population,3);
    % 计算子类的适应度
    for i = 1:1:populationSize
        %fitnessValues_pop(i,1) = i;
        fitnessValues_chi(i,1) = i;
    end
    fitnessValues_chi(:,2) = GA_evaluateFitness(children);
    % 排序
    fitnessValues_popSorted = sortrows(fitnessValues_pop,2,'descend');
    %fitnessValues_popSorted
    fitnessValues_chiSorted = sortrows(fitnessValues_chi,2,'descend');
    %fitnessValues_chiSorted
    %最佳个体的永久保留，二元锦标赛会丢失最佳个体
    if fitnessValues_popSorted(1,2) >= fitnessValues_chiSorted(1,2)
        if bestIndividual_fitnessValue < fitnessValues_popSorted(1,2)
            bestIndividual_fitnessValue = fitnessValues_popSorted(1,2);
            bestIndividual = population(:,:,fitnessValues_popSorted(1,1));
        end
        %disp('\033[31mbestscore:\033[39m');
        % 本轮种群最优
        fprintf('round_bestIndividual_fitnessValue:%f\n',fitnessValues_popSorted(1,2))
        % 历史种群最优
        fprintf('history_bestIndividual_fitnessValue:%f\n\n',bestIndividual_fitnessValue);
    else
        if bestIndividual_fitnessValue < fitnessValues_chiSorted(1,2)
            bestIndividual_fitnessValue = fitnessValues_chiSorted(1,2);
            bestIndividual = children(:,:,fitnessValues_chiSorted(1,1));
        end
        % 本轮种群最优
        fprintf('round_bestIndividual_fitnessValue:%f\n',fitnessValues_chiSorted(1,2))
        % 历史种群最优
        fprintf('history_bestIndividual_fitnessValue:%f\n',bestIndividual_fitnessValue);
    end
    % 个体的替换
    population_end = zeros(size(population));
    %popSize = size(population,1);
    saveNum = floor(populationSize*replaceRate);
    for i = 1:1:saveNum
        population_end(:,:,i) = population(:,:,fitnessValues_popSorted(i,1));
    end
    for i = saveNum+1:1:populationSize
        population_end(:,:,i) = children(:,:,fitnessValues_chiSorted(i-saveNum,1));
    end
end